<?php
include ('chek.php');
//删掉管理员

if($input->get('do')=='delete'){
    $aid=$input->get('aid');
    $sql="delete from admin WHERE aid='{$aid}'";
    if($aid==$_SESSION['l_id']){
        die('不能删除自己');
        exit;
    }
    $is=$db->query($sql);

    if($is){
        header('location:blog.php');
    }
    else{
        die(' 删除失败！');
    }
}

//获取数据
$sql="select * from admin";
$sql_result=$db->query($sql);
$rows=array();
while ($row=$sql_result->fetch_array(MYSQLI_ASSOC)){
    $rows[]=$row;
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8"/>
    <title>管理员管理</title>
    <?php
    include ('../headr.php');
    ?>
</head>
<body>
    <?php
    include ('nav.php');
    ?>
    <div class="container">
        <div class="row">
            <h2>管理员管理<a href="blog_add.php" class="pull-right btn btn-default">添加管理</a></h2>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>管理</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach($rows as $row):?>
                    <tr>
                        <td><?php echo $row['aid'];?></td>
                        <td><?php echo $row['auser'];?></td>
                        <td>
                            <a href="blog_add.php?aid=<?php echo $row['aid'];?>">修改</a>
                            <a onclick="return confirm('你要确定删除吗？')" href="blog.php?do=delete&aid=<?php echo $row['aid'];?>">删除</a>
                        </td>
                    </tr>
                <?php endforeach;?>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>
